// pages/auth/auth.js
import {wx_login} from '../../utils/asyncWx.js'
import regeneratorRuntime from '../../lib/runtime/runtime'
import{getUserToken}from '../../service/order_user'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  async getUserInfo(e){
    try {
      console.log(e)
    //1.获取用户信息
    const {encryptedData,iv,rawData,signature}=e.detail;
    //2.获取登录后的code
    const {code}=await wx_login();
    //2.1整合请求携带参数
    const QueryParams={encryptedData,iv,rawData,signature,code};
    //3.发送请求获取用户token
    const {token}=await getUserToken({data:QueryParams,method:"post"});
    //4.把token存到缓存中,z在跳转回上一个页面
    wx.setStorageSync('token', token);
    wx.navigateBack({
      delta:1
    });
    } catch (error) {
      console.log(err)
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

 
})